import { stringify } from 'qs';
import request from '../utils/request';

export async function findAllJob(params) {
  return request(`/alarm/job?${stringify(params)}`);
}

export async function getJob(name) {
  return request(`/alarm/job/${encodeURIComponent(name)}`);
}

export async function getAlertJobInfo(name) {
  return request(`/alarm/job/${encodeURIComponent(name)}/info`);
}

export async function addJob(params) {
  return request(`/alarm/job`, { method: "POST", body: params });
}

export async function updateJob(name, params) {
  return request(`/alarm/job/${encodeURIComponent(name)}`, { method: "PUT", body: params });
}

export async function validatorCron(params) {
  return request(`/alarm/validator/cron?${stringify(params)}`);
}

export async function setJobStatus(name, params) {
  return request(`/alarm/job/${encodeURIComponent(name)}/status`, { method: "PUT", body: params });
}

export async function batchSetJobStatus(params) {
  return request('/alarm/job/batch/status', { method: "PUT", body: params });
}

export async function delJob(name) {
  return request(`/alarm/job/${encodeURIComponent(name)}`, { method: "DELETE" });
}

export async function batchDelJob(names) {
  return request(`/alarm/job/batch?${stringify({ names }, { indices: false })}`, { method: "DELETE" });
}

export async function testEsQuery(params) {
  return request(`/alarm/test/es_query`, { method: "POST", body: params });
}

export async function testMetricData(params) {
  return request(`/alarm/test/metric_data`, { method: "POST", body: params });
}






